package gggameserver.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

class StreamGobbler extends Thread {
	InputStream is;
	String type;
	StringBuilder sb;

	StreamGobbler(InputStream is, String type, StringBuilder sb) {
		this.is = is;
		this.type = type;
		this.sb = sb;
	}

	public void run() {
		try {
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			String line = null;
			while ((line = br.readLine()) != null)
				synchronized (sb) {
					sb.append(type + ">" + line + '\r' + '\n');
				}
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
}